/*
 *	This file is part of Lounge-Cast.
 *
 *  Author:  	Markus Moormann
 *	E-mail:  	mmoorman@uni-osnabrueck.de
 *	Copyright:	University of Osnabrueck (Zentrum Virtuos)
 * 	Website:	www.uni-osnabrueck.de
 *	Date:		16.02.2011
 *
 *	Lounge-Cast is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *	Lounge-Cast is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Lounge-Cast.  If not, see <http://www.gnu.org/licenses/>.
 */
package multimedia.control.business
{
	import com.adobe.cairngorm.business.ServiceLocator;
	
	import multimedia.model.vo.PlayerVO;
	import multimedia.model.vo.PlaylistVO;
	import multimedia.model.vo.UserVO;
	
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	import mx.rpc.remoting.RemoteObject;
	
	/**
	 * delegate handling all service call for playlists
	 */
	public class PlaylistDelegate
	{
		/**
		 * the responder which should be called on result or fault
		 */
		private var responder:IResponder;
		/**
		 * the service to call
		 */
		private var service:RemoteObject = ServiceLocator.getInstance().getRemoteObject("playlist");
		
		/**
		 * constructor
		 * 
		 * @param responder the responder which should be called on result or fault
		 */
		public function PlaylistDelegate(responder:IResponder)
		{
			this.responder = responder;
		}

		/**
		 * service call for saving a playlist
		 * 
		 * @param playlist the playlist to save
		 * @param user the user who added the playlist
		 */
		public function savePlaylist(playlist:PlaylistVO, user:UserVO):void
		{
			var token:AsyncToken = service.savePlaylist(playlist, user);
			token.addResponder(responder);
		}
		
		/**
		 * service call for getting all playlists a certain user can edit
		 * 
		 * @param user the user to get the playlists for
		 */
		public function getPlaylists(user:UserVO):void
		{
			var token:AsyncToken = service.getPlaylists(user);
			token.addResponder(responder);
		}
		
		/**
		 * service call for updating a playlist
		 * 
		 * @param playlist the playlist to update
		 */
		public function updatePlaylist(playlist:PlaylistVO):void
		{
			var token:AsyncToken = service.updatePlaylist(playlist);
			token.addResponder(responder);
		}
		
		/**
		 * service call for getting all playlists belonging to a certain player
		 * 
		 * @param player the player to get the playlists for
		 */
		public function getPlaylistsForPlayer(player:PlayerVO):void
		{
			var token:AsyncToken = service.getPlaylistsForPlayer(player);
			token.addResponder(responder);
		}
		
		/**
		 * service call for deleting a playlist
		 * 
		 * @param playlist the playlist to delete
		 */
		public function deletePlaylist(playlist:PlaylistVO):void
		{
			var token:AsyncToken = service.deletePlaylist(playlist);
			token.addResponder(responder);
		}
		
	}
}